# Maintainer: Konstantin Gizdov <arch at kge dot pw>

pkgname=intel-oneapi-tbb
pkgver=2021.8.0
_debpkgrel=25334
pkgrel=1
pkgdesc="Intel oneAPI Threading Building Blocks"
arch=('loong64' 'x86_64')
url='https://software.intel.com/content/www/us/en/develop/tools/oneapi.html'
license=("custom")
source=("https://apt.repos.intel.com/oneapi/pool/main/${pkgname}-${pkgver}-${pkgver}-${_debpkgrel}_amd64.deb"
        "https://apt.repos.intel.com/oneapi/pool/main/${pkgname}-devel-${pkgver}-${pkgver}-${_debpkgrel}_amd64.deb"
        "https://apt.repos.intel.com/oneapi/pool/main/${pkgname}-common-${pkgver}-${pkgver}-${_debpkgrel}_all.deb"
        "https://apt.repos.intel.com/oneapi/pool/main/${pkgname}-common-devel-${pkgver}-${pkgver}-${_debpkgrel}_all.deb")
b2sums=('20135709c9066fa31ceae0baa576ad62188c6de04b8c8dab650024f9671528b55af585c17705bcc116546e11435c9b6394dc08bc81b15ced4091096f50bfd03e'
        '5d2b34482a57414d2ad7b9a5a14382431717e0165c4dd23b171347f4940628b169a8604de989e63e207f66354129a5760aad81c5fc37d0faffbba6bbaa4edfef'
        '4b38e22b6acf84f09f51211e2d946280d9781df6702e5ea02bd778a811747df76cf3d27b1ea50dba00266b9cf70e9f2b4d5af2a96d57be2cd7cf59ffb4b5ebed'
        '5ca3774d5fe21f65536255742bc924ca7ea591d572e3fbcdca6f1e7b593a451a2eae5c7df0782c2a918888c8580a40d6d5f3156f36d52240cce5146489478d96')
depends=('intel-oneapi-common')
conflicts=('intel-oneapi-basekit')
noextract=(
    "${pkgname}-${pkgver}-${pkgver}-${_debpkgrel}_amd64.deb"
    "${pkgname}-devel-${pkgver}-${pkgver}-${_debpkgrel}_amd64.deb"
    "${pkgname}-common-${pkgver}-${pkgver}-${_debpkgrel}_all.deb"
    "${pkgname}-common-devel-${pkgver}-${pkgver}-${_debpkgrel}_all.deb"
)

package() {
    cd "${srcdir}"
    ar x "${srcdir}/${pkgname}-${pkgver}-${pkgver}-${_debpkgrel}_amd64.deb"
    tar xvf data.tar.xz -C "${pkgdir}"
    rm data.tar.xz

    ar x "${srcdir}/${pkgname}-devel-${pkgver}-${pkgver}-${_debpkgrel}_amd64.deb"
    tar xvf data.tar.xz -C "${pkgdir}"
    rm data.tar.xz

    ar x "${srcdir}/${pkgname}-common-${pkgver}-${pkgver}-${_debpkgrel}_all.deb"
    tar xvf data.tar.xz -C "${pkgdir}"
    rm data.tar.xz

    ar x "${srcdir}/${pkgname}-common-devel-${pkgver}-${pkgver}-${_debpkgrel}_all.deb"
    tar xvf data.tar.xz -C "${pkgdir}"
    rm data.tar.xz

    # drop conda binaries
    rm -r "${pkgdir}"/opt/intel/oneapi/conda_channel

    # latest symlink
    local _prefix=/opt/intel/oneapi/tbb
    ln -s "${_prefix}/${pkgver}" "${pkgdir}/${_prefix}/latest"

    # fix pkgconfig
    sed "s@prefix=.*@prefix=${_prefix}/latest@g" \
        -i "${pkgdir}/${_prefix}/${pkgver}"/lib/pkgconfig/tbb.pc
    install -d "${pkgdir}"/usr/share/pkgconfig
    ln -s "${_prefix}"/latest/lib/pkgconfig/tbb.pc "${pkgdir}"/usr/share/pkgconfig/tbb.pc

    # ldconfig
    install -d "${pkgdir}"/etc/ld.so.conf.d
    echo "${_prefix}"/latest/"$(sed -n 's/libdir=${prefix}\///p' "${pkgdir}/${_prefix}/${pkgver}"/lib/pkgconfig/tbb.pc)" \
        > "${pkgdir}/etc/ld.so.conf.d/${pkgname}.conf"

    install -d "${pkgdir}"/usr/share/licenses/"${pkgname}"
    ln -s /usr/share/licenses/intel-oneapi "${pkgdir}"/usr/share/licenses/"${pkgname}"/oneapi
    ln -s /opt/intel/oneapi/tbb/"{pkgver}"/licensing "${pkgdir}"/usr/share/licenses/"${pkgname}"/tbb
}
